package com.iujin.magic;

import org.springframework.stereotype.Component;
import org.ssssssss.magicapi.model.RequestEntity;
import org.ssssssss.magicapi.provider.ResultProvider;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Component
public class CustomJsonProvider implements ResultProvider {
    @Override
    public Object buildResult(RequestEntity requestEntity, int code, String message, Object data) {
        return new HashMap<String,Object>(){
            {
                put("code",code==1?200:code);
                put("success",code==1?true:false);
                put("msg",message);
                put("data",data);
            }
        };
    }

    @Override
    public Object buildPageResult(long total, List<Map<String, Object>> data) {
        return new HashMap<String,Object>(){
            {
                put("total", total);
                put("records", data);
            }
        };
    }
}
